package algorithms;

import game.AbstractOthelloPosition;

public class OthelloEvaluatorCountPiecesLimitMoves implements OthelloEvaluatorInterface{

		private boolean _player;
		
		public OthelloEvaluatorCountPiecesLimitMoves(boolean player){
			_player = player;
		}
	
		@Override
		public int evaluate(AbstractOthelloPosition p){
			AbstractOthelloPosition p2 = (AbstractOthelloPosition) p.clone();
			p2.changePlayer();
			char playerColor = (_player) ? 'W' : 'B';
			char opponentColor = (_player) ? 'B' : 'W';
			if(p.getMoves().isEmpty() && p2.getMoves().isEmpty()){
				int result = p.getCount(playerColor) - p.getCount(opponentColor);
				int isEnd = 10000;
				if(result < 0){
					isEnd = -isEnd;
				}
				return  result + isEnd;
			}
			if(p.toMove() == _player){
				return  p.getCount(playerColor) - p.getCount(opponentColor) - p2.getMoves().size(); 
			}else{
				return  p.getCount(playerColor) - p.getCount(opponentColor);//+ p2.getMoves().size();
			}
			
		}
}
